#include"Httpserver.hpp"
#include"HttpProtocol.hpp"

void Login(HttpRequest &req,HttpReponse &resp)
{
    LOG(Logevel::INFO)<<"进入登录模块"<<req.Path()<<", "<<req.Args();
    std::string req_args=req.Args();


    std::string body=req.GetContent("wwwroot/success.html");
    resp.Setcode(200);
    resp.SetHeader("Content-Length",std::to_string(body.size()));    
    resp.SetHeader("Content-Type","text/html");    

    resp.SetHeader("Set-Cookie","usename=xiaowang&passwd=123456");
    resp.SetBody(body);
    
}

void Register(HttpRequest &req, HttpReponse &resp)
{
    LOG(Logevel::INFO)<<"进入注册模块"<<req.Path()<<", "<<req.Args();
}

void Search(HttpRequest &req, HttpReponse &resp)
{
    LOG(Logevel::DEBUG) << "进入搜索模块" << req.Path() << ", " << req.Args();
}

void Test(HttpRequest &req, HttpReponse &resp)
{
   
    LOG(Logevel::DEBUG) << "进入测试模块" << req.Path() << ", " << req.Args();
}




int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        std::cout<<"Usage: "<<argv[0]<<" port"<<std::endl;
        return 1;
    }

    auto httpserver=std::make_unique<HttpServer>(std::stoi(argv[1]));

    httpserver->Resgiter("/login",Login);
    httpserver->Resgiter("/register",Register);
    httpserver->Resgiter("/search",Search);


    httpserver->Start();
    


    return 0;
}